package com.zhuang.collection.map;

import java.util.HashMap;
import java.util.Map;

public class MapMethod {
	public static void main(String[] args) {

		Map<Object, Object> map = new HashMap<>();
		map.put("1", new Book("java", 100));// OK
		map.put("2", "二号");// 替换-> 一会分析源码
		map.put("3", "三号");// OK
		map.put("4", "四号");// OK
		map.put("5", null);// OK
		map.put(null, "空");// OK
		map.put("6", "六号");// OK
		map.put("7", "七号");
		System.out.println("map=" + map);

		// remove:根据键删除映射关系
		map.remove(null);
		System.out.println("map=" + map);
		// get：根据键获取值
		Object val = map.get("2");
		System.out.println("val=" + val);
		// size:获取元素个数
		System.out.println("k-v=" + map.size());
		// isEmpty:判断个数是否为 0
		System.out.println(map.isEmpty());// F
		// clear:清除 k-v
		// map.clear();
		System.out.println("map=" + map);
		// containsKey:查找键是否存在
		System.out.println("结果=" + map.containsKey("6"));// T
	}
}

class Book {
	private String name;
	private int num;

	public Book(String name, int num) {
		this.name = name;
		this.num = num;
	}

	@Override
	public String toString() {
		return "Book{" + "name='" + name + '\'' + ", num=" + num + '}';
	}
}
